#!/bin/sh
set -euo pipefail

if [[ ! -f "${CONF_PATH}/config.yaml" ]]; then
	./uplink setup
fi

RUN_PARAMS="${RUN_PARAMS:-} --config ${CONF_PATH}"

if [[ -n "${API_KEY:-}" ]]; then
	RUN_PARAMS="${RUN_PARAMS} --api-key ${API_KEY}"
fi

if [ -n "${SATELLITE_ADDR:-}" ]; then
	RUN_PARAMS="${RUN_PARAMS} --overlay-addr $SATELLITE_ADDR"
	RUN_PARAMS="${RUN_PARAMS} --pointer-db-addr $SATELLITE_ADDR"
fi

exec ./uplink run $RUN_PARAMS "$@"
